#include <iostream>
#include <string>
#include <vector>
using namespace std;

string longestCommonPrefix(vector<string>& strs) 
{
    if (strs.empty()) 
    {
        return "";
    }
    int n = strs.size();
    string ans = strs[0];
    for (int i = 1; i < n; i++) 
    {
        int j = ans.size() - 1;
        while (ans[j] != strs[i][j]) 
        {
            ans.pop_back();
            j--;
        }
    }
    return ans;
}

int main()
{
	vector<string> v = { "abca","abc","abca","abc","abcc" };
	cout << longestCommonPrefix(v) << endl;
	return 0;
}